 <body>
<div class="bjy-admin-nav">
	<i class="fa fa-home"></i> 首页
	&gt;
	菜单管理
</div>
<ul id="myTab" class="nav nav-tabs">
   	<li class="active">
		<a href="#home" data-toggle="tab">菜单列表</a>
   	</li>
   	<li>
		<a href="javascript:;" onclick="add()">添加菜单</a>
	</li>
</ul>

	<div id="myTabContent" class="tab-content">
	   <div class="tab-pane fade in active" id="home">
			<table class="table table-striped table-bordered table-hover table-condensed">
				<tr>
					<th>菜单名</th>
					<th>连接</th>
					<th>操作</th>
				</tr>
				<{volist name="list" id="vo"}>
					<tr>
						<td><{$vo._name}></td>
						<td><{$vo.mca}></td>
						<td>
							<{if condition="$vo.pid eq 0"}>
							<a href="javascript:;" navId="<{$vo.id}>" onclick="add_child(this)">添加子菜单</a> |
							<{/if}>
							<a href="javascript:;" navId="<{$vo.id}>" navName="<{$vo.name}>" navMca="<{$vo.mca}>" navIco="<{$vo.ico}>" onclick="edit(this)">修改</a> |
							<a href="javascript:;" class="delete" data-id="<{$vo.id}>">删除</a>
						</td>
					</tr>
				<{/volist}>
			</table>
	   </div>
	</div>

<!-- 添加菜单模态框开始 -->
<div class="modal fade" id="bjy-add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		 <div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
					&times;
				</button>
				<h4 class="modal-title" id="myModalLabel">
					添加菜单
				</h4>
			</div>
			<div class="modal-body">
				<input type="hidden" name="pid" value="0">
				<table class="table table-striped table-bordered table-hover table-condensed">
					<tr>
						<th width="12%">菜单名：</th>
						<td>
							<input class="form-control" type="text" name="addName" placeholder="请输入菜单名">
						</td>
					</tr>
					<tr>
						<th>链接：</th>
						<td>
							<input class="form-control" type="text" name="addMca" placeholder="请输入链接"> 输入模块/控制器/方法即可 例如 admin/nav/index
						</td>
					</tr>
					<tr>
						<th>图标：</th>
						<td>
							<input class="form-control" type="text" name="addIco" placeholder="请输入图标">
							font-awesome图标 输入fa fa- 后边的即可
						</td>
					</tr>
					<tr>
						<th></th>
						<td>
							<input class="btn btn-success sub-add" type="button" value="添加">
						</td>
					</tr>
				</table>
			</div>
		</div>
	</div>
</div>
<!-- 添加菜单模态框结束 -->

<!-- 修改菜单模态框开始 -->
<div class="modal fade" id="bjy-edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		 <div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
					&times;
				</button>
				<h4 class="modal-title" id="myModalLabel">
					修改菜单
				</h4>
			</div>
			<div class="modal-body">
				<input type="hidden" name="id">
				<table class="table table-striped table-bordered table-hover table-condensed">
					<tr>
						<th width="12%">菜单名：</th>
						<td>
							<input class="form-control" type="text" name="name">
						</td>
					</tr>
					<tr>
						<th>连接：</th>
						<td>
							<input class="form-control" type="text" name="mca"> 输入模块/控制器/方法即可 例如 Admin/Nav/index
						</td>
					</tr>
					<tr>
						<th>图标：</th>
						<td>
							<input class="form-control" type="text" name="ico">
							font-awesome图标 输入fa fa- 后边的即可
						</td>
					</tr>
					<tr>
						<th></th>
						<td>
							<input class="btn btn-success submit-save" type="button" value="修改">
						</td>
					</tr>
				</table>
			</div>
		</div>
	</div>
</div>
<!-- 修改菜单模态框结束 -->
<!-- 自定义alert -->
<div class="modal fade" id="comfirm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<h4 class="modal-title" id="myModalLabel">
					确定删除?
				</h4>
			</div>
			<div class="modal-body">
				<div class="center-block">
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					<button type="button" class="btn btn-primary yes">确认</button>
				</div>
			</div>
		</div>
	</div>
</div>
<!-- 自定义alert -->
<script>
// 添加菜单
function add(){
	$("input[name='addName'],input[name='addMca'],input[name='addIco']").val(null);
	$("input[name='pid']").val(0);
	$('#bjy-add').modal('show');
}

// 添加子菜单
function add_child(obj){
	$("input[name='pid']").val($(obj).attr('navId'));
	$("input[name='addName']").val(null);
	$("input[name='addMca']").val(null);
	$("input[name='addIco']").val(null);
	$('#bjy-add').modal('show');
}

// 修改菜单
function edit(obj){
	$("input[name='id']").val($(obj).attr('navId'));
	$("input[name='name']").val($(obj).attr('navName'));
	$("input[name='mca']").val($(obj).attr('navMca'));
	$("input[name='ico']").val($(obj).attr('navIco'));
	$('#bjy-edit').modal('show');
}

$(function(){
	//菜单删除
    $('.delete').click(function(){
		this_delete = $(this);
		$('#comfirm').modal('show');
    })

	$('.yes').click(function(){
		//防止多次点击
		var yes = $(this);
		$(this).addClass('disabled');
		$.post("<{:url('delete_nav')}>",{'id':this_delete.data('id')},function(data){
			if(data.code){
				$('.btn-default').trigger('click');
				yes.removeClass('disabled');
				this_delete.parents('tr').remove();
			}else{
				alert(data.msg);
			}
		},'json');
	})

    /*	菜单添加
	 */
    $('.sub-add').click(function(){
        var addName = $("input[name='addName']").val();
        var addMca = $("input[name='addMca']").val();
        var addIco = $("input[name='addIco']").val();
        var pid = $("input[name='pid']").val();
        if(addName == ''){
        	alert('请填写菜单名！');
        	return false;
        }
        if(addMca == ''){
        	alert('请填写链接！');
        	return false;
        }

        $.post("<{:url('add_nav')}>",{'addName':addName,'addMca':addMca,'addIco':addIco,'pid':pid,},function(data){
            if(data.code){
                alert(data.msg);
                window.location.href="<{:url('nav')}>";
            }else{
                alert(data.msg);
            }
        },'json');
    })
    /*	菜单修改
	 */
    $('.submit-save').click(function(){
        var name = $("input[name='name']").val();
        var mca = $("input[name='mca']").val();
        var ico = $("input[name='ico']").val();
        var id = $("input[name='id']").val();
        if(name == ''){
        	alert('请填写菜单名！');
        	return false;
        }
        if(mca == ''){
        	alert('请填写链接！');
        	return false;
        }

        $.post("<{:url('update_nav')}>",{'name':name,'ico':ico,'mca':mca,'id':id},function(data){
            if(data.code){
                alert(data.msg);
                window.location.href="<{:url('nav')}>";
            }else{
                alert(data.msg);
            }
        },'json');
    })
})
</script>